package hongsong.eqixueweb.learncenter;

import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;

import hongsong.eqixueweb.common.BasicAction;
import hongsong.eqixueweb.common.DateFromat;
import hongsong.eqixueweb.common.Keywords;
import hongsong.eqixueweb.common.ReadFile;
import hongsong.eqixueweb.common.TestNGListenerScreen;
import hongsong.eqixueweb.login.AdminLoginTest;
import static hongsong.eqixueweb.common.PagesXpath.*;

@Listeners({ TestNGListenerScreen.class })
public class CourseCenter extends BasicAction {

	/*
	 * 新增课程
	 */
	public void addcourse(String cname) {

		BasicAction.sleep(2);
		webwait.until(ExpectedConditions.presenceOfElementLocated(By
				.id("createCourse")));
		wAction = driver.findElement(By.id("createCourse"));
		((JavascriptExecutor) driver).executeScript("arguments[0].click();",
				wAction);
		BasicAction.sleep(2);
		// driver.findElement(By.id("createCourse")).click();
		driver.findElement(By.id("coursename")).click();
		BasicAction.sleep(2);
		driver.findElement(By.id("coursename")).sendKeys(cname);

		// 点击上传图片
		webwait.until(ExpectedConditions.presenceOfElementLocated(By
				.xpath("//*[@id=\"page-wrapper\"]/div[3]/div/div/div/div/form/div[4]/div/div/label/span[1]")));
		wAction = driver
				.findElement(By
						.xpath("//*[@id=\"page-wrapper\"]/div[3]/div/div/div/div/form/div[4]/div/div/label/span[1]"));
		((JavascriptExecutor) driver).executeScript("arguments[0].click();",
				wAction);
		BasicAction.sleep(2);

		ReadFile rf = new ReadFile();
		File file = new File(this.getClass().getResource("/filetemp/elogo.jpg")
				.getPath());
		rf.fileUpload("firefox", file);
		BasicAction.sleep(2);

		// 选择添加标签
		webwait.until(ExpectedConditions.presenceOfElementLocated(By
				.xpath("//*[@id=\"page-wrapper\"]/div[3]/div/div/div/div/form/div[8]/div/span/span[1]/span")));
		wAction = driver
				.findElement(By
						.xpath("//*[@id=\"page-wrapper\"]/div[3]/div/div/div/div/form/div[8]/div/span/span[1]/span"));
		((JavascriptExecutor) driver).executeScript("arguments[0].click();",
				wAction);
		// driver.findElement(
		// By.xpath("//*[@id=\"page-wrapper\"]/div[3]/div/div/div/div/form/div[8]/div/span/span[1]/span"))
		// .click();
		BasicAction.sleep(3);
		driver.findElement(By.xpath("/html/body/span/span/span/ul/li[1]"))
				.click();
		BasicAction.sleep(3);

		webwait.until(ExpectedConditions.presenceOfElementLocated(By
				.xpath("//*[@id=\"page-wrapper\"]/div[3]/div/div/div/div/form/div[8]/div/span/span[1]/span")));
		wAction = driver
				.findElement(By
						.xpath("//*[@id=\"page-wrapper\"]/div[3]/div/div/div/div/form/div[8]/div/span/span[1]/span"));
		((JavascriptExecutor) driver).executeScript("arguments[0].click();",
				wAction);
		BasicAction.sleep(3);
		driver.findElement(By.xpath("/html/body/span/span/span/ul/li[2]"))
				.click();
		BasicAction.sleep(3);

		webwait.until(ExpectedConditions.presenceOfElementLocated(By
				.xpath("//*[@id=\"page-wrapper\"]/div[3]/div/div/div/div/form/div[8]/div/span/span[1]/span")));
		wAction = driver
				.findElement(By
						.xpath("//*[@id=\"page-wrapper\"]/div[3]/div/div/div/div/form/div[8]/div/span/span[1]/span"));
		((JavascriptExecutor) driver).executeScript("arguments[0].click();",
				wAction);
		BasicAction.sleep(3);
		driver.findElement(By.xpath("/html/body/span/span/span/ul/li[3]"))
				.click();
		BasicAction.sleep(3);

		// 新增标签并添加
		// driver.findElement(
		// By.xpath("//*[@id=\"page-wrapper\"]/div[3]/div/div/div/div/form/div[8]/div/span/span[1]/span"))
		// .click();
		// driver.findElement(
		// By.xpath("//*[@id=\"page-wrapper\"]/div[3]/div/div/div/div/form/div[8]/div/span/span[1]/span"))
		// .sendKeys("技术  ");
		// BasicAction.sleep(3);
		// driver.findElement(
		// By.xpath("//*[@id=\"page-wrapper\"]/div[3]/div/div/div/div/form/div[8]/div/span/span[1]/span"))
		// .sendKeys(Keys.ENTER);
		// BasicAction.sleep(3);
		// driver.findElement(
		// By.xpath("//*[@id=\"page-wrapper\"]/div[3]/div/div/div/div/form/div[8]/div/span/span[1]/span"))
		// .sendKeys(Keys.SPACE);
		// BasicAction.sleep(3);
		//
		// driver.findElement(
		// By.xpath("//*[@id=\"page-wrapper\"]/div[3]/div/div/div/div/form/div[8]/div/span/span[1]/span"))
		// .click();
		// driver.findElement(
		// By.xpath("//*[@id=\"page-wrapper\"]/div[3]/div/div/div/div/form/div[8]/div/span/span[1]/span"))
		// .sendKeys("信息  ");
		// BasicAction.sleep(3);
		// driver.findElement(
		// By.xpath("//*[@id=\"page-wrapper\"]/div[3]/div/div/div/div/form/div[8]/div/span/span[1]/span"))
		// .sendKeys(Keys.ENTER);
		// BasicAction.sleep(3);
		// driver.findElement(
		// By.xpath("//*[@id=\"page-wrapper\"]/div[3]/div/div/div/div/form/div[8]/div/span/span[1]/span"))
		// .sendKeys(Keys.SPACE);
		// BasicAction.sleep(3);
		//
		// driver.findElement(
		// By.xpath("//*[@id=\"page-wrapper\"]/div[3]/div/div/div/div/form/div[8]/div/span/span[1]/span"))
		// .click();
		// driver.findElement(
		// By.xpath("//*[@id=\"page-wrapper\"]/div[3]/div/div/div/div/form/div[8]/div/span/span[1]/span"))
		// .sendKeys("网络  ");
		// BasicAction.sleep(3);
		// driver.findElement(
		// By.xpath("//*[@id=\"page-wrapper\"]/div[3]/div/div/div/div/form/div[8]/div/span/span[1]/span"))
		// .sendKeys(Keys.ENTER);
		// BasicAction.sleep(3);
		// driver.findElement(
		// By.xpath("//*[@id=\"page-wrapper\"]/div[3]/div/div/div/div/form/div[8]/div/span/span[1]/span"))
		// .sendKeys(Keys.SPACE);
		// BasicAction.sleep(3);
		webwait.until(ExpectedConditions.presenceOfElementLocated(By
				.id("btnOK")));
		wAction = driver.findElement(By.id("btnOK"));
		((JavascriptExecutor) driver).executeScript("arguments[0].click();",
				wAction);
		BasicAction.sleep(10);
	}

	/*
	 * 修改课程
	 */
	public void upcourse(String cname) {
		webwait.until(ExpectedConditions.presenceOfElementLocated(By
				.xpath("//*[@id=\"video_main\"]/div[3]/button[2]")));
		wAction = driver.findElement(By
				.xpath("//*[@id=\"video_main\"]/div[3]/button[2]"));
		((JavascriptExecutor) driver).executeScript("arguments[0].click();",
				wAction);
		BasicAction.sleep(3);
		// 修改课程名称
		driver.findElement(By.id("coursename")).clear();
		BasicAction.sleep(2);
		driver.findElement(By.id("coursename")).sendKeys(cname);
		BasicAction.sleep(3);
		// 修改学习权限
		webwait.until(ExpectedConditions.presenceOfElementLocated(By
				.id("isAccessAllNo")));
		wAction = driver.findElement(By.id("isAccessAllNo"));
		((JavascriptExecutor) driver).executeScript("arguments[0].click();",
				wAction);

		webwait.until(ExpectedConditions.presenceOfElementLocated(By
				.id("addUserBtn")));
		wAction = driver.findElement(By.id("addUserBtn"));
		((JavascriptExecutor) driver).executeScript("arguments[0].click();",
				wAction);

		BasicAction.sleep(3);
		driver.findElement(
				By.xpath("//*[@id=\"tab-1_examinee\"]/div/div[1]/input"))
				.click();
		driver.findElement(
				By.xpath("//*[@id=\"tab-1_examinee\"]/div/div[1]/input"))
				.clear();
		driver.findElement(
				By.xpath("//*[@id=\"tab-1_examinee\"]/div/div[1]/input"))
				.sendKeys(new ReadFile().readpro(Keywords.web_s_admin));
		driver.findElement(By.id("tab-1_search_examinee")).click();
		BasicAction.sleep(3);
		driver.findElement(
				By.xpath("//*[@id=\"tab-1_examinee\"]/div/div[2]/div/div[2]/dl/div/dd/div/div/div[2]/span[1]"))
				.click();
		BasicAction.sleep(3);
		driver.findElement(By.id("submit_examinee")).click();
		// BasicAction.sleep(3);
		webwait.until(ExpectedConditions.presenceOfElementLocated(By
				.id("btnOK")));
		wAction = driver.findElement(By.id("btnOK"));
		((JavascriptExecutor) driver).executeScript("arguments[0].click();",
				wAction);
		BasicAction.sleep(10);
	}

	/*
	 * 课程资源—添加课件、添加链接、添加作业、修改阶段名称、删除阶段名称、新增阶段
	 */
	public void addresource(String aname) {

		// 添加课件
		webwait.until(ExpectedConditions.presenceOfElementLocated(By.id("abc")));
		wAction = driver.findElement(By.id("abc"));
		((JavascriptExecutor) driver).executeScript("arguments[0].click();",
				wAction);
		BasicAction.sleep(3);
		driver.findElement(By.id("name")).clear();
		driver.findElement(By.id("name")).sendKeys(aname);
		// 选择文件
		driver.findElement(
				By.xpath("//*[@id=\"page-wrapper\"]/div[3]/div/div/div/div/div/div[3]/div/a[1]"))
				.click();
		BasicAction.sleep(3);
		// driver.findElement(By.id("select2-fileType-container")).click();
		Select select = new Select(driver.findElement(By.id("fileType")));
		select.selectByIndex(1);
		driver.findElement(
				By.xpath("//*[@id=\"chooseDocModal\"]/div/div/div[2]/div[1]/div[3]/div/span/button"))
				.click();
		BasicAction.sleep(3);
		driver.findElement(By.id("fileList")).click();
		BasicAction.sleep(3);
		// 预览
		driver.findElement(By.id("viewer")).click();
		BasicAction.sleep(3);
		driver.findElement(
				By.xpath("//*[@id=\"previewVideo\"]/div/div/div[3]/button"))
				.click();

		webwait.until(ExpectedConditions.presenceOfElementLocated(By
				.id("btnOK")));
		wAction = driver.findElement(By.id("btnOK"));
		((JavascriptExecutor) driver).executeScript("arguments[0].click();",
				wAction);
		BasicAction.sleep(3);

		// 添加链接
		webwait.until(ExpectedConditions.presenceOfElementLocated(By
				.xpath("//*[@id=\"nestable_list_1\"]/ol/li/span/button[2]")));
		wAction = driver.findElement(By
				.xpath("//*[@id=\"nestable_list_1\"]/ol/li/span/button[2]"));
		((JavascriptExecutor) driver).executeScript("arguments[0].click();",
				wAction);
		BasicAction.sleep(3);
		driver.findElement(By.id("name")).clear();
		driver.findElement(By.id("name")).sendKeys(aname);
		BasicAction.sleep(3);
		driver.findElement(By.id("linkAddress")).clear();
		driver.findElement(By.id("linkAddress")).sendKeys("www.hongsong.cn");
		BasicAction.sleep(3);
		driver.findElement(
				By.xpath("//*[@id=\"page-wrapper\"]/div[3]/div/div/div/div/div/div[7]/div/button"))
				.click();
		BasicAction.sleep(3);

		// 添加作业
		webwait.until(ExpectedConditions.presenceOfElementLocated(By
				.xpath("//*[@id=\"nestable_list_1\"]/ol/li/span/button[3]")));
		wAction = driver.findElement(By
				.xpath("//*[@id=\"nestable_list_1\"]/ol/li/span/button[3]"));
		((JavascriptExecutor) driver).executeScript("arguments[0].click();",
				wAction);
		BasicAction.sleep(3);
		driver.findElement(By.id("hw_name")).clear();
		driver.findElement(By.id("hw_name")).sendKeys(aname);

		webwait.until(ExpectedConditions.presenceOfElementLocated(By
				.xpath("//*[@id=\"hw_homework\"]/form/div/div/div[3]/a[1]")));
		wAction = driver.findElement(By
				.xpath("//*[@id=\"hw_homework\"]/form/div/div/div[3]/a[1]"));
		((JavascriptExecutor) driver).executeScript("arguments[0].click();",
				wAction);
		BasicAction.sleep(3);

		// 选择作业题
		webwait.until(ExpectedConditions.presenceOfElementLocated(By
				.xpath("//*[@id=\"nohomeWorkLabel\"]/div/p/a")));
		wAction = driver.findElement(By
				.xpath("//*[@id=\"nohomeWorkLabel\"]/div/p/a"));
		((JavascriptExecutor) driver).executeScript("arguments[0].click();",
				wAction);
		BasicAction.sleep(3);
		driver.findElement(By.id("allDelBoxMo")).click();
		BasicAction.sleep(3);
		driver.findElement(By.id("a_bindQuestion")).click();
		BasicAction.sleep(3);
		// 作业预览
		driver.findElement(By.id("homework_view")).click();
		BasicAction.sleep(3);

		// String currentWindow=driver.getWindowHandle(); //获取当前浏览器窗口句柄
		// System.out.println("当前窗口："+currentWindow);
		Set<String> handles = driver.getWindowHandles(); // 获取当前浏览器的所有窗口句柄
		List<String> it = new ArrayList<String>(handles);
		String next = it.get(1); // 此处是第一个窗口句柄
		System.out.println("第二个窗口句柄：" + next);
		WebDriver window = driver.switchTo().window(next);
		window.close();
		driver.switchTo().window(it.get(0)); // 回到原来页面

		// 取消选择（单个）
		driver.findElement(By.xpath("//*[@id=\"dataClass\"]/tr[1]/td[7]/a"))
				.click();
		BasicAction.sleep(3);
		// 批量解绑
		driver.findElement(By.id("allDelBox")).click();
		BasicAction.sleep(3);
		driver.findElement(By.id("deleteQuestionBtn")).click();
		BasicAction.sleep(3);
		webwait.until(ExpectedConditions.presenceOfElementLocated(By
				.xpath("/html/body/div[10]/div[7]/button[2]")));
		wAction = driver.findElement(By
				.xpath("/html/body/div[10]/div[7]/button[2]"));
		((JavascriptExecutor) driver).executeScript("arguments[0].click();",
				wAction);
		BasicAction.sleep(3);

		// 再次选择作业题
		webwait.until(ExpectedConditions.presenceOfElementLocated(By
				.id("bindBtn")));
		wAction = driver.findElement(By.id("bindBtn"));
		((JavascriptExecutor) driver).executeScript("arguments[0].click();",
				wAction);
		BasicAction.sleep(3);
		driver.findElement(By.id("allDelBoxMo")).click();
		BasicAction.sleep(3);
		driver.findElement(By.id("a_bindQuestion")).click();
		BasicAction.sleep(3);

		// 返回课件管理
		webwait.until(ExpectedConditions.presenceOfElementLocated(By
				.xpath("//*[@id=\"page-wrapper\"]/div[3]/div/div/div/div[1]/div/div[2]/a[2]")));
		wAction = driver
				.findElement(By
						.xpath("//*[@id=\"page-wrapper\"]/div[3]/div/div/div/div[1]/div/div[2]/a[2]"));
		((JavascriptExecutor) driver).executeScript("arguments[0].click();",
				wAction);

		BasicAction.sleep(3);

		// 修改阶段名称

		// driver.findElement(
		// By.xpath("//*[@id=\"nestable_list_1\"]/ol/li/span/button[4]"))
		// .click();
		webwait.until(ExpectedConditions.presenceOfElementLocated(By
				.xpath("//*[@id=\"nestable_list_1\"]/ol/li/span/button[4]")));
		wAction = driver.findElement(By
				.xpath("//*[@id=\"nestable_list_1\"]/ol/li/span/button[4]"));
		((JavascriptExecutor) driver).executeScript("arguments[0].click();",
				wAction);
		BasicAction.sleep(3);
		driver.findElement(By.id("modStageName")).clear();
		driver.findElement(By.id("modStageName")).sendKeys(aname);
		BasicAction.sleep(3);
		webwait.until(ExpectedConditions.presenceOfElementLocated(By
				.xpath("//*[@id=\"form2\"]/div/div/div[3]/a[1]")));
		wAction = driver.findElement(By
				.xpath("//*[@id=\"form2\"]/div/div/div[3]/a[1]"));
		((JavascriptExecutor) driver).executeScript("arguments[0].click();",
				wAction);
		BasicAction.sleep(3);

	}

	/*
	 * 课程阶段-添加并删除
	 */
	public void addphase(String name) {
		// 添加学习阶段
		webwait.until(ExpectedConditions.presenceOfElementLocated(By
				.xpath("//*[@id=\"tab-1\"]/div/button")));
		wAction = driver.findElement(By.xpath("//*[@id=\"tab-1\"]/div/button"));
		((JavascriptExecutor) driver).executeScript("arguments[0].click();",
				wAction);
		// driver.findElement(By.xpath("//*[@id=\"tab-1\"]/div/button")).click();
		BasicAction.sleep(3);
		driver.findElement(By.id("stageName")).clear();
		driver.findElement(By.id("stageName")).sendKeys(name);
		BasicAction.sleep(3);
		webwait.until(ExpectedConditions.presenceOfElementLocated(By
				.xpath("//*[@id=\"form1\"]/div/div/div[3]/a[1]")));
		wAction = driver.findElement(By
				.xpath("//*[@id=\"form1\"]/div/div/div[3]/a[1]"));
		((JavascriptExecutor) driver).executeScript("arguments[0].click();",
				wAction);
		BasicAction.sleep(3);

		// 删除学习阶段
		webwait.until(ExpectedConditions.presenceOfElementLocated(By
				.xpath("//*[@id=\"nestable_list_2\"]/ol/li/span/button[5]")));
		wAction = driver.findElement(By
				.xpath("//*[@id=\"nestable_list_2\"]/ol/li/span/button[5]"));
		((JavascriptExecutor) driver).executeScript("arguments[0].click();",
				wAction);
		BasicAction.sleep(3);
	}

	/*
	 * 课程资源—修改、预览、复制、删除课件
	 */
	public void upcouware(String upname) {
		// 修改课件
		webwait.until(ExpectedConditions.presenceOfElementLocated(By
				.xpath("//*[@id=\"nestable_list_1\"]/ol/li/ol/li[1]/span/button[1]")));
		wAction = driver
				.findElement(By
						.xpath("//*[@id=\"nestable_list_1\"]/ol/li/ol/li[1]/span/button[1]"));
		((JavascriptExecutor) driver).executeScript("arguments[0].click();",
				wAction);
		BasicAction.sleep(3);
		driver.findElement(By.id("name")).clear();
		driver.findElement(By.id("name")).sendKeys(upname);
		webwait.until(ExpectedConditions.presenceOfElementLocated(By
				.id("btnOK")));
		wAction = driver.findElement(By.id("btnOK"));
		((JavascriptExecutor) driver).executeScript("arguments[0].click();",
				wAction);
		BasicAction.sleep(3);

		// 预览课件
		webwait.until(ExpectedConditions.presenceOfElementLocated(By
				.xpath("//*[@id=\"nestable_list_1\"]/ol/li/ol/li[1]/span/button[2]")));
		wAction = driver
				.findElement(By
						.xpath("//*[@id=\"nestable_list_1\"]/ol/li/ol/li[1]/span/button[2]"));
		((JavascriptExecutor) driver).executeScript("arguments[0].click();",
				wAction);

		BasicAction.sleep(3);
		driver.findElement(
				By.xpath("//*[@id=\"previewVideo\"]/div/div/div[3]/button"))
				.click();
		BasicAction.sleep(3);

		// 复制课件
		webwait.until(ExpectedConditions.presenceOfElementLocated(By
				.xpath("//*[@id=\"nestable_list_1\"]/ol/li/ol/li[1]/span/button[3]")));
		wAction = driver
				.findElement(By
						.xpath("//*[@id=\"nestable_list_1\"]/ol/li/ol/li[1]/span/button[3]"));
		((JavascriptExecutor) driver).executeScript("arguments[0].click();",
				wAction);

		BasicAction.sleep(3);
		driver.findElement(By.xpath("//*[@id=\"form3\"]/div/div/div[3]/a[1]"))
				.click();
		BasicAction.sleep(3);

		// 删除课件（复制的）
		webwait.until(ExpectedConditions.presenceOfElementLocated(By
				.xpath("//*[@id=\"nestable_list_1\"]/ol/li/ol/li[4]/span/button[4]")));
		wAction = driver
				.findElement(By
						.xpath("//*[@id=\"nestable_list_1\"]/ol/li/ol/li[4]/span/button[4]"));
		((JavascriptExecutor) driver).executeScript("arguments[0].click();",
				wAction);

		BasicAction.sleep(3);
		webwait.until(ExpectedConditions.presenceOfElementLocated(By
				.xpath("/html/body/div[20]/div[7]/button[2]")));
		wAction = driver.findElement(By
				.xpath("/html/body/div[20]/div[7]/button[2]"));
		((JavascriptExecutor) driver).executeScript("arguments[0].click();",
				wAction);
		BasicAction.sleep(3);
	}

	/*
	 * 课程资源—修改、复制、删除链接
	 */
	public void uplink(String linkname) {
		// 修改链接
		// driver.findElement(
		// By.xpath("//*[@id=\"nestable_list_1\"]/ol/li/ol/li[2]/span/button[1]"))
		// .click();
		webwait.until(ExpectedConditions.presenceOfElementLocated(By
				.xpath("//*[@id=\"nestable_list_1\"]/ol/li/ol/li[2]/span/button[1]")));
		wAction = driver
				.findElement(By
						.xpath("//*[@id=\"nestable_list_1\"]/ol/li/ol/li[2]/span/button[1]"));
		((JavascriptExecutor) driver).executeScript("arguments[0].click();",
				wAction);
		BasicAction.sleep(3);
		driver.findElement(By.id("name")).clear();
		driver.findElement(By.id("name")).sendKeys(linkname);
		BasicAction.sleep(3);
		driver.findElement(By.id("linkAddress")).clear();
		driver.findElement(By.id("linkAddress")).sendKeys("www.hongsong.cn");
		BasicAction.sleep(3);
		driver.findElement(
				By.xpath("//*[@id=\"page-wrapper\"]/div[3]/div/div/div/div/div/div[7]/div/button"))
				.click();
		BasicAction.sleep(3);
		// 复制链接
		webwait.until(ExpectedConditions.presenceOfElementLocated(By
				.xpath("//*[@id=\"nestable_list_1\"]/ol/li/ol/li[2]/span/button[2]")));
		wAction = driver
				.findElement(By
						.xpath("//*[@id=\"nestable_list_1\"]/ol/li/ol/li[2]/span/button[2]"));
		((JavascriptExecutor) driver).executeScript("arguments[0].click();",
				wAction);
		BasicAction.sleep(3);
		webwait.until(ExpectedConditions.presenceOfElementLocated(By
				.xpath("//*[@id=\"form3\"]/div/div/div[3]/a[1]")));
		wAction = driver.findElement(By
				.xpath("//*[@id=\"form3\"]/div/div/div[3]/a[1]"));
		((JavascriptExecutor) driver).executeScript("arguments[0].click();",
				wAction);
		BasicAction.sleep(3);
		// 删除链接（复制的）
		// driver.findElement(
		// By.xpath("//*[@id=\"nestable_list_1\"]/ol/li/ol/li[4]/span/button[3]"))
		// .click();
		// BasicAction.sleep(3);
		// webwait.until(ExpectedConditions.presenceOfElementLocated(By
		// .xpath("/html/body/div[20]/div[7]/button[2]")));
		// wAction =
		// driver.findElement(By.xpath("/html/body/div[20]/div[7]/button[2]"));
		// ((JavascriptExecutor) driver).executeScript("arguments[0].click();",
		// wAction);
		// BasicAction.sleep(3);

	}

	/*
	 * 课程资源—修改作业名称、修改作业题、预览、复制、删除作业
	 */

	public void upoperation(String opname) {
		// 修改作业名称
		webwait.until(ExpectedConditions.presenceOfElementLocated(By
				.xpath("//*[@id=\"nestable_list_1\"]/ol/li/ol/li[3]/span/button[1]")));
		wAction = driver
				.findElement(By
						.xpath("//*[@id=\"nestable_list_1\"]/ol/li/ol/li[3]/span/button[1]"));
		((JavascriptExecutor) driver).executeScript("arguments[0].click();",
				wAction);
		BasicAction.sleep(3);
		driver.findElement(By.id("hw_name")).clear();
		driver.findElement(By.id("hw_name")).sendKeys(opname);
		BasicAction.sleep(3);

		webwait.until(ExpectedConditions.presenceOfElementLocated(By
				.xpath("//*[@id=\"hw_homework\"]/form/div/div/div[3]/a[1]")));
		wAction = driver.findElement(By
				.xpath("//*[@id=\"hw_homework\"]/form/div/div/div[3]/a[1]"));
		((JavascriptExecutor) driver).executeScript("arguments[0].click();",
				wAction);
		BasicAction.sleep(3);
		// 修改作业题
		webwait.until(ExpectedConditions.presenceOfElementLocated(By
				.xpath("//*[@id=\"nestable_list_1\"]/ol/li/ol/li[3]/span/button[2]")));
		wAction = driver
				.findElement(By
						.xpath("//*[@id=\"nestable_list_1\"]/ol/li/ol/li[3]/span/button[2]"));
		((JavascriptExecutor) driver).executeScript("arguments[0].click();",
				wAction);

		BasicAction.sleep(3);
		driver.findElement(By.id("bindBtn")).click();
		BasicAction.sleep(3);
		webwait.until(ExpectedConditions.presenceOfElementLocated(By
				.xpath("//*[@id=\"dataQuestion\"]/tr[1]/td[1]/div/div/ins")));
		wAction = driver.findElement(By
				.xpath("//*[@id=\"dataQuestion\"]/tr[1]/td[1]/div/div/ins"));
		((JavascriptExecutor) driver).executeScript("arguments[0].click();",
				wAction);

		driver.findElement(By.id("a_bindQuestion")).click();
		BasicAction.sleep(3);
		webwait.until(ExpectedConditions.presenceOfElementLocated(By
				.xpath("//*[@id=\"page-wrapper\"]/div[3]/div/div/div/div[1]/div/div[2]/a[2]")));
		wAction = driver
				.findElement(By
						.xpath("//*[@id=\"page-wrapper\"]/div[3]/div/div/div/div[1]/div/div[2]/a[2]"));
		((JavascriptExecutor) driver).executeScript("arguments[0].click();",
				wAction);

		BasicAction.sleep(3);

		// 预览作业

		webwait.until(ExpectedConditions.presenceOfElementLocated(By
				.xpath("//*[@id=\"nestable_list_1\"]/ol/li/ol/li[3]/span/a")));
		wAction = driver.findElement(By
				.xpath("//*[@id=\"nestable_list_1\"]/ol/li/ol/li[3]/span/a"));
		((JavascriptExecutor) driver).executeScript("arguments[0].click();",
				wAction);
		BasicAction.sleep(3);
		Set<String> handles = driver.getWindowHandles(); // 获取当前浏览器的所有窗口句柄
		BasicAction.sleep(3);
		List<String> it = new ArrayList<String>(handles);
		String next = it.get(1); // 此处是第一个窗口句柄
		System.out.println("第二个窗口句柄：" + next);
		BasicAction.sleep(3);
		WebDriver window = driver.switchTo().window(next);
		window.close();
		driver.switchTo().window(it.get(0)); // 回到原来页面

		// 复制作业

		webwait.until(ExpectedConditions.presenceOfElementLocated(By
				.xpath("//*[@id=\"nestable_list_1\"]/ol/li/ol/li[3]/span/button[3]")));
		wAction = driver
				.findElement(By
						.xpath("//*[@id=\"nestable_list_1\"]/ol/li/ol/li[3]/span/button[3]"));
		((JavascriptExecutor) driver).executeScript("arguments[0].click();",
				wAction);
		BasicAction.sleep(3);
		webwait.until(ExpectedConditions.presenceOfElementLocated(By
				.xpath("//*[@id=\"form5\"]/div/div/div[3]/a[1]")));
		wAction = driver.findElement(By
				.xpath("//*[@id=\"form5\"]/div/div/div[3]/a[1]"));
		((JavascriptExecutor) driver).executeScript("arguments[0].click();",
				wAction);
		BasicAction.sleep(3);
		// 删除作业
		// driver.findElement(
		// By.xpath("//*[@id=\"nestable_list_1\"]/ol/li/ol/li[4]/span/button[4]"))
		// .click();
		// BasicAction.sleep(3);
		// driver.findElement(By.xpath("/html/body/div[20]/div[7]/button[2]"))
		// .click();
		// BasicAction.sleep(3);

	}

	/*
	 * 发布课程
	 */
	public void pubcourse() {

		webwait.until(ExpectedConditions.presenceOfElementLocated(By
				.id("publishCourse")));
		wAction = driver.findElement(By.id("publishCourse"));
		((JavascriptExecutor) driver).executeScript("arguments[0].click();",
				wAction);
		BasicAction.sleep(3);
		webwait.until(
				ExpectedConditions.presenceOfElementLocated(By
						.xpath("//*[@id=\"course_publish_info\"]/div/div/div[2]/div/div[2]/div/div/ins")))
				.click();
		webwait.until(
				ExpectedConditions.presenceOfElementLocated(By
						.id("publishCourseOkBtn"))).click();

	}

	/*
	 * 设为热门课程
	 */
	public void hotcourse() {
		BasicAction.sleep(3);
		webwait.until(ExpectedConditions.presenceOfElementLocated(By
				.xpath("//*[@id=\"video_main\"]/div[3]/button[3]")));
		wAction = driver.findElement(By
				.xpath("//*[@id=\"video_main\"]/div[3]/button[3]"));
		((JavascriptExecutor) driver).executeScript("arguments[0].click();",
				wAction);
		BasicAction.sleep(3);
		webwait.until(ExpectedConditions.presenceOfElementLocated(By
				.xpath("/html/body/div[20]/div[7]/button[2]")));
		wAction = driver.findElement(By
				.xpath("/html/body/div[20]/div[7]/button[2]"));
		((JavascriptExecutor) driver).executeScript("arguments[0].click();",
				wAction);
		BasicAction.sleep(3);
		// 返回课程详情
		driver.findElement(By.xpath("//*[@id=\"video_main\"]/div[3]/button[5]"))
				.click();
		BasicAction.sleep(3);
	}

	/*
	 * 删除课程
	 */
	public void delcourse() {
		BasicAction.sleep(3);
		webwait.until(ExpectedConditions.presenceOfElementLocated(By
				.xpath("//*[@id=\"video_main\"]/div[3]/button[4]")));
		wAction = driver.findElement(By
				.xpath("//*[@id=\"video_main\"]/div[3]/button[4]"));
		((JavascriptExecutor) driver).executeScript("arguments[0].click();",
				wAction);
		BasicAction.sleep(3);
		webwait.until(ExpectedConditions.presenceOfElementLocated(By
				.xpath("/html/body/div[20]/div[7]/button[2]")));
		wAction = driver.findElement(By
				.xpath("/html/body/div[20]/div[7]/button[2]"));
		((JavascriptExecutor) driver).executeScript("arguments[0].click();",
				wAction);
		BasicAction.sleep(3);
	}

	/*
	 * 学习课程
	 */
	public void stucourse() {
		BasicAction.sleep(3);
		driver.findElement(
				By.xpath("//*[@id=\"courseList\"]/div[1]/div/a/div[1]/img"))
				.click();
		// 视频
		BasicAction.sleep(3);
		driver.findElement(
				By.xpath("//*[@id=\"directory\"]/div/dl/div/dd[1]/a")).click();
		BasicAction.sleep(3);

		webwait.until(ExpectedConditions.presenceOfElementLocated(By
				.xpath("//*[@id=\"page-wrapper\"]/div/div/div/div[1]/div[1]/h3/a[1]")));
		wAction = driver
				.findElement(By
						.xpath("//*[@id=\"page-wrapper\"]/div/div/div/div[1]/div[1]/h3/a[1]"));
		((JavascriptExecutor) driver).executeScript("arguments[0].click();",
				wAction);
		BasicAction.sleep(3);

		// 作业
		webwait.until(ExpectedConditions.presenceOfElementLocated(By
				.xpath("//*[@id=\"directory\"]/div/dl/div/dd[2]/a")));
		wAction = driver.findElement(By
				.xpath("//*[@id=\"directory\"]/div/dl/div/dd[2]/a"));
		((JavascriptExecutor) driver).executeScript("arguments[0].click();",
				wAction);
		// driver.findElement(
		// By.xpath("//*[@id=\"directory\"]/div/dl/div/dd[2]/a")).click();
		BasicAction.sleep(3);
		webwait.until(ExpectedConditions.presenceOfElementLocated(By
				.xpath("//*[@id=\"1\"]/div[1]/div/section/div[1]/div/label")));

		wAction = driver.findElement(By
				.xpath("//*[@id=\"1\"]/div[1]/div/section/div[1]/div/label"));
		((JavascriptExecutor) driver).executeScript("arguments[0].click();",
				wAction);
		BasicAction.sleep(2);
		webwait.until(ExpectedConditions.presenceOfElementLocated(By
				.xpath("//*[@id=\"2\"]/div[1]/div/section/div[1]/div/label")));
		wAction = driver.findElement(By
				.xpath("//*[@id=\"2\"]/div[1]/div/section/div[1]/div/label"));
		((JavascriptExecutor) driver).executeScript("arguments[0].click();",
				wAction);
		BasicAction.sleep(2);
		webwait.until(ExpectedConditions.presenceOfElementLocated(By
				.xpath("//*[@id=\"page-wrapper\"]/div/div/div/div[1]/div[2]/div[1]/div/button")));
		wAction = driver
				.findElement(By
						.xpath("//*[@id=\"page-wrapper\"]/div/div/div/div[1]/div[2]/div[1]/div/button"));
		((JavascriptExecutor) driver).executeScript("arguments[0].click();",
				wAction);
		// driver.findElement(
		// By.xpath("//*[@id=\"page-wrapper\"]/div/div/div/div[1]/div[2]/div[1]/div/button"))
		// .click();
		BasicAction.sleep(2);
		webwait.until(ExpectedConditions.presenceOfElementLocated(By
				.xpath("//*[@id=\"page-wrapper\"]/div/div/div/div[1]/div[1]/h3/a[1]")));
		wAction = driver
				.findElement(By
						.xpath("//*[@id=\"page-wrapper\"]/div/div/div/div[1]/div[1]/h3/a[1]"));
		((JavascriptExecutor) driver).executeScript("arguments[0].click();",
				wAction);
		// driver.findElement(
		// By.xpath("//*[@id=\"page-wrapper\"]/div/div/div/div[1]/div[1]/h3/a[1]"))
		// .click();
		BasicAction.sleep(2);
	}

	/*
	 * 评论课程
	 */
	public void comcourse() {
		webwait.until(ExpectedConditions.presenceOfElementLocated(By
				.xpath("//*[@id=\"page-wrapper\"]/div[3]/div[2]/div[2]/div/ul/li[2]/a")));
		wAction = driver
				.findElement(By
						.xpath("//*[@id=\"page-wrapper\"]/div[3]/div[2]/div[2]/div/ul/li[2]/a"));
		((JavascriptExecutor) driver).executeScript("arguments[0].click();",
				wAction);
		// driver.findElement(
		// By.xpath("//*[@id=\"page-wrapper\"]/div[3]/div[2]/div[2]/div/ul/li[2]/a"))
		// .click();
		BasicAction.sleep(2);
		driver.findElement(
				By.xpath("//*[@id=\"tab-2\"]/div/div[1]/div[3]/button"))
				.click();
		BasicAction.sleep(2);

		driver.findElement(By.id("inlineRadio1")).click();
		BasicAction.sleep(2);
		driver.findElement(By.id("remarkVal")).click();
		BasicAction.sleep(2);
		driver.findElement(By.id("remarkVal")).sendKeys("好评课程");
		BasicAction.sleep(2);
		driver.findElement(By.id("remarkButton")).click();
		BasicAction.sleep(2);

	}

	/*
	 * 查询课程
	 */
	public void selcourse(String name) {
		// 点击课程中心菜单
		webwait.until(
				ExpectedConditions.presenceOfElementLocated(By
						.id(xpath_coursecenter))).click();
		BasicAction.sleep(2);
		driver.findElement(By.id("coursename")).click();
		driver.findElement(By.id("coursename")).clear();
		driver.findElement(By.id("coursename")).sendKeys(name);
		BasicAction.sleep(2);
		driver.findElement(
				By.xpath("//*[@id=\"page-wrapper\"]/div[3]/div/div/div/div[1]/div/div/div/div[1]/span"))
				.click();
		BasicAction.sleep(2);

	}

	@Test
	public void t() {
		ReadFile rf = new ReadFile();
		String account = rf.readpro(Keywords.web_s_admin);
		String pwd = rf.readpro(Keywords.web_s_pwd);
		AdminLoginTest login = new AdminLoginTest();
		login.webadminlogin(account, pwd);
		login.companychoise(account);
		BasicAction.sleep(3);
		// 点击学习中心菜单
		webwait.until(
				ExpectedConditions.presenceOfElementLocated(By
						.id(xpath_learncenter))).click();
		// 点击课程中心菜单
		webwait.until(
				ExpectedConditions.presenceOfElementLocated(By
						.id(xpath_coursecenter))).click();

		DateFromat df = new DateFromat();
		String couname = "课程" + df.getdate();
		// 新增课程
		this.addcourse(couname);
		// 修改课程
		this.upcourse("修改课程" + df.getdate());
		// 添加课程资源
		this.addresource("资源" + df.getdate());
		// 课程阶段-添加、删除阶段
		this.addphase("阶段" + df.getdate());
		// 课程资源—修改、预览、复制、删除课件
		this.upcouware("课件" + df.getdate());
		// 课程资源—修改、复制、删除链接
		this.uplink("链接" + df.getdate());
		// 课程资源-修改作业名称、修改作业题、预览、复制、删除作业
		this.upoperation("作业" + df.getdate());
		// 发布课程
		this.pubcourse();
		// 设为热门
		this.hotcourse();
		// 删除课程
		webwait.until(
				ExpectedConditions.presenceOfElementLocated(By
						.id(xpath_coursecenter))).click();
		this.addcourse(couname);
		this.delcourse();
		// 学习课程
		this.stucourse();
		// 评论课程
		this.comcourse();
		// 查询课程
		this.selcourse(couname);
	}
}
